更换glibc版本 | 您所在的位置:网站首页 › glibc 版本过高 › 更换glibc版本 |
文章目录
更换glibc版本1.下载glibc2.下载patchelf3.更换glibc4.备注
更换glibc版本
因为pwn学习堆的知识点的时候需要使用到glibc2.23的环境,但是我的ubuntu20.04的glibc是2.31,所以需要更换到低版本的glibc 1.下载glibc在github上下载glibc-all-in-one项目: $ git clone https://github.com/matrix1001/glibc-all-in-one.git进入目录,然后运行update_list脚本: $ ./update_list [+] Common list has been save to "list" [+] Old-release list has been save to "old_list"查看所有的glibc版本: $ cat list 2.23-0ubuntu11.3_amd64 2.23-0ubuntu11.3_i386 2.23-0ubuntu3_amd64 2.23-0ubuntu3_i386 2.27-3ubuntu1.2_amd64 2.27-3ubuntu1.2_i386 2.27-3ubuntu1.4_amd64 2.27-3ubuntu1.4_i386 2.27-3ubuntu1_amd64 2.27-3ubuntu1_i386 2.31-0ubuntu9.2_amd64 2.31-0ubuntu9.2_i386 2.31-0ubuntu9_amd64我选择2.23的版本下载: $ ./download 2.23-0ubuntu3_amd64 Getting 2.23-0ubuntu3_amd64 -> Location: https://mirror.tuna.tsinghua.edu.cn/ubuntu/pool/main/g/glibc/libc6_2.23-0ubuntu3_amd64.deb -> Downloading libc binary package -> Extracting libc binary package -> Package saved to libs/2.23-0ubuntu3_amd64 -> Location: https://mirror.tuna.tsinghua.edu.cn/ubuntu/pool/main/g/glibc/libc6-dbg_2.23-0ubuntu3_amd64.deb -> Downloading libc debug package -> Extracting libc debug package -> Package saved to libs/2.23-0ubuntu3_amd64/.debug下载完了可以在glibc-all-in-one/libs下看到: $ ls 2.23-0ubuntu3_amd64 2.下载patchelfpatchelf在GitHub上:https://github.com/NixOS/patchelf.git $ git clone https://github.com/NixOS/patchelf.git进入patchelf的目录,安装如下的工具: $ sudo apt-get install autoconf automake libtool然后: ./bootstrap.sh ./configure make sudo make install make check安装完后可以看到patchelf的选项: $ patchelf syntax: patchelf [--set-interpreter FILENAME] [--page-size SIZE] [--print-interpreter] [--print-soname] Prints 'DT_SONAME' entry of .dynamic section. Raises an error if DT_SONAME doesn't exist [--set-soname SONAME] Sets 'DT_SONAME' entry to SONAME. [--set-rpath RPATH] [--add-rpath RPATH] [--remove-rpath] [--shrink-rpath] [--allowed-rpath-prefixes PREFIXES] With '--shrink-rpath', reject rpath entries not starting with the allowed prefix [--print-rpath] [--force-rpath] [--add-needed LIBRARY] [--remove-needed LIBRARY] [--replace-needed LIBRARY NEW_LIBRARY] [--print-needed] [--no-default-lib] [--clear-symbol-version SYMBOL] [--output FILE] [--debug] [--version] FILENAME... 3.更换glibc我的libc的文件夹位置: /root/home/tools/glibc-all-in-one/libs/2.23-0ubuntu3_amd64libc名字: ld-2.23.so下面对某个程序的glibc进行替换。 c代码如下: #include int main(void) { void *ptr, *ptr1; ptr = malloc(0x10); //分配第一个0x10的chunk malloc(0x10); //分配第二个0x10的chunk *(long long *)((long long)ptr - 0x8) = 0x41; // 修改第一个块的size域 free(ptr); ptr1 = malloc(0x30); // 实现 extend,控制了第二个块的内容 return 0; }进行编译: gcc test.c -o test看一下原来的glibc版本: $ ldd test linux-vdso.so.1 (0x00007ffff7fcd000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffff7dbf000) /lib64/ld-linux-x86-64.so.2 (0x00007ffff7fcf000)下面进行patchelf替换: $ patchelf --set-interpreter /root/home/tools/glibc-all-in-one/libs/2.23-0ubuntu3_amd64/ld-2.23.so --set-rpath /root/home/tools/glibc-all-in-one/libs/2.23-0ubuntu3_amd64 test再看一下ldd: $ ldd test linux-vdso.so.1 (0x00007ffff7fcd000) libc.so.6 => /root/home/tools/glibc-all-in-one/libs/2.23-0ubuntu3_amd64/libc.so.6 (0x00007ffff7bf9000) /root/home/tools/glibc-all-in-one/libs/2.23-0ubuntu3_amd64/ld-2.23.so => /lib64/ld-linux-x86-64.so.2 (0x00007ffff7fcf000)发现成功替换! 4.备注如果更换glibc后LibcSearcher找不到对应的libc版本,那就参考如下的教程进行添加本地的glibc: https://github.com/niklasb/libc-database |
CopyRight 2018-2019 实验室设备网 版权所有 |